package entities 
{
	import examples.Box2DWorld;
	import pure.engine.entity.IEntity;
	import pure.engine.entity.IEntityFactory;
	import pure.engine.renderer.AnimationRenderer;
	import pure.engine.renderer.IAnimation;
	
	import Box2D.Collision.Shapes.b2PolygonShape;
	import Box2D.Collision.b2AABB;
	import Box2D.Common.Math.b2Vec2;
	import Box2D.Dynamics.b2Body;
	import Box2D.Dynamics.b2BodyDef;
	import Box2D.Dynamics.b2DebugDraw;
	import Box2D.Dynamics.b2FixtureDef;
	import Box2D.Dynamics.b2World;
	
	/**
	 * ...
	 * @author Pure
	 */
public class PhysicsBoy  implements IEntityFactory 
{
	
	
	public function produce(entity:IEntity, wx:Number, wy:Number, args:Array = null):IEntity
	{
		var card:IAnimation = entity.createAnimationRenderer('colonist_32_32','card',true);
		card.play('left_stand');

		var bodyDef:b2BodyDef = new b2BodyDef();
		bodyDef.type = b2Body.b2_dynamicBody;
		bodyDef.position.Set(wx / 30, wy / 30);
		var body:b2Body=Box2DWorld.world.CreateBody(bodyDef);

		var shape:b2PolygonShape = new b2PolygonShape();
		shape.SetAsBox(entity.realRect.width / 2 / 30, entity.realRect.height / 2 / 30);

		body.SetUserData(entity);
		var fixtureDef:b2FixtureDef = new b2FixtureDef();
		fixtureDef.shape=shape;
		fixtureDef.density = 1;
		fixtureDef.friction = 0.3;
		fixtureDef.restitution = 0.4;
		body.CreateFixture(fixtureDef);

		return entity;
	}
}

}